package com.mtons.mblog.base.utils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.UUID;

public class CommonUtils {

    public static String getUUID() {
        System.out.println(UUID.randomUUID());
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
    }

    /**
     * 获得当前日期
     * @return
     */
    public static Date getNowTime(){
        final LocalDateTime localDateTime = LocalDateTime.now();
        final Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

    /**
     * 格式化日期
     * @return
     */
    public static Date getStrTime(String dateStr, String pattern){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
        LocalDateTime parseTime = LocalDateTime.parse(dateStr, dateTimeFormatter);
        Instant instant = parseTime.atZone(ZoneId.systemDefault()).toInstant();
        return Date.from(instant);
    }

}
